home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / programm / prog_a2m / mpydsp56 / multiply.s56 < prev   
Text File  |  1995-05-02  |  3KB  |  128 lines

  1. ;*****************************************************************
  2. ;* DSP 56001 microprocessor source code for a 48bit (2^24.2^-24) 
  3. ;* real number multiplier.            
  4. ;*
  5. ;* X memory contains the whole part of number. Y memory contains
  6. ;* the fractional part. X1 and Y1 are the whole number registers. 
  7. ;* X0 and Y0 are the fractional number register.
  8. ;*
  9. ;* - Resolution of Numbers -
  10. ;* 24 bits for whole number part and 24 bits for the fractional part.
  11. ;*
  12. ;* - Memory use -
  13. ;* Sx = Whole and fractional number source.
  14. ;* R1 = Results of multiply.
  15. ;*
  16. ;* x:aw = s1 whole number
  17. ;* y:af = s1 fractional number
  18. ;* x:bw = s2 whole number
  19. ;* y:bf = s2 fractional number
  20. ;* x:cw = r1 whole number results
  21. ;* y:cf = r1 fractional number results
  22. ;*
  23. ;* Source values will no longer have a negative sign after program has
  24. ;* made it's calculations.
  25. ;*
  26. ;* - Register use - 
  27. ;* X1, X0, Y1, Y0, A, and B are trashed, so save them.
  28. ;*
  29. ;* - Signed numbers - 
  30. ;* If either whole number or the fractional part is signed negative
  31. ;* then the whole and fractional part number will be negative.
  32. ;* Example:
  33. ;* x:address =  2, y:address = -.123456 = -2.123456
  34. ;* x:address = -2, y:address =  .123456 = -2.123456
  35. ;* x:address =  2, y:address =  .123456 =  2.123456
  36. ;*
  37. ;* Created by Robert W. Stiles. Freeware! Users are free to modify the
  38. ;* code to your taste. However you must include your name and what part
  39. ;* of the source code that was modifed. In other words keep a history
  40. ;* record. Some modification are required if you wish to make this a
  41. ;* program sub-routine. It's currently written to run as a program.
  42. ;*
  43. ;* Created with Hisoft DSP Assembler Verion 1.0 17 April 1994
  44.  
  45.     org    p:$40
  46.  
  47. multiply_48bits    
  48.     move    #>0,x0
  49.     move    x0,x:s1_nf    ; Clear sign flags
  50.     move    x0,x:s2_nf
  51.     move    #1,b2        ; For setting negate flag.
  52.  
  53. _ck_s1_fraction
  54.     btst    #23,y:af            ; Verifiy sign of fraction
  55.     jcc    _ck_s1_whole
  56.     move    y:af,a0
  57.     neg    a
  58.     move    b2,x:s1_nf
  59.     move    a0,y:af
  60.  
  61. _ck_s1_whole            ; Verify sign of whole number.
  62.     btst    #23,x:aw
  63.     jcc    _ck_s2_fraction
  64.     move    x:aw,a0        ; Get the value.
  65.     neg    a        ; Make positive.
  66.     move    b2,x:s1_nf    ; Set negate flag.
  67.     move    a0,x:aw        ; Save value.
  68.  
  69. _ck_s2_fraction
  70.     btst    #23,y:bf
  71.     jcc    _ck_s2_whole
  72.     move    y:bf,a0
  73.     neg    a
  74.     move     b2,x:s2_nf
  75.     move    a0,y:bf
  76.  
  77. _ck_s2_whole
  78.     btst    #23,x:bw
  79.     jcc    _do_calc
  80.     move    x:bw,a0
  81.     neg    a
  82.     move    b2,x:s2_nf
  83.     move    a0,x:bw    
  84.  
  85. _do_calc
  86.     move    l:aw,x        ; Load value to be multiplied.
  87.     move    l:bw,y              ; Load value to be multiplied.
  88.     clr    a        ; Clear used registers.
  89.     clr    b        ; Clear used registers.
  90.     mpyr    x0,y0,a        ; Multiply the s1 s2 fractions.
  91.     move    a1,a0        ; Place results in fraction register.
  92.     move    #0,a1        ; Clear whole register.
  93.     mpy    x1,y0,b        ; Multiply s1 whole and s2 fraction.
  94.     mac    y1,x0,b        ; Multiply/Add s2 whole and s1 fraction.
  95.     addr    a,b        ; Add and correct results.
  96.     mpy    x1,y1,a        ; Multiply s1 whole and s2 whole.
  97.     asr    a        ; Correct results.
  98.     move    a0,a1        ; Move results into whole register.
  99.     move    #0,a0        ; Clear fraction register.
  100.     add    a,b        ; Sum the results.
  101.     
  102.     move    x:s1_nf,x0    ; Check to see what sign it will be.
  103.     move    x:s2_nf,a
  104.     sub    x0,a
  105.     jeq    _no_sign
  106.     neg    b        ; Make a negative value.
  107. _no_sign
  108.     move    b,l:cw        ; Save results r1.
  109. alldone    jmp    alldone
  110.     
  111.     
  112. ;*****************************************************************
  113.  
  114.     org    x:$00
  115.  
  116. aw    dc    -2
  117. bw    dc    2
  118. cw    dc    0
  119. s1_nf    dc    0
  120. s2_nf    dc    0
  121.  
  122.     org    y:$00
  123.  
  124. af    dc    -.123456
  125. bf    dc    .123456
  126. cf    dc    0
  127.  
  128.     end